clear all
set more off

local out2="\outregsQJE\"
local SSA="\Data_and_Codes\"
cd "\workfiles"


use step001_QJE_2, clear

*** join SSA data
joinby firm_id time using "`SSA'CGR_2006q1_2019q1_clean_ONLYINPSADD.dta", unmatched(master)
tab _merge
drop _merge

joinby firm_id time using "`SSA'CGR_2006q1_2019q1_clean_ONLYINPSWAGE.dta", unmatched(master)
tab _merge
drop _merge

tsset firm_id time

*** define treatment as given inflation TIMES treatment status
gen Treat=treatment_old*infl

*** winsorize actual and expected price changes
winsor dpre, gen(dpre_w) p(0.02)
winsor dprez, gen(dprez_w) p(0.02)

local controls0=" l2.dprez_w  i.l2.sitimp5 i.l2.occtot i.l2.sitgen i.l2.promig i.l2.liquid "	

*** restrict the sample only to the period with treatment and control groups
keep if time>=217 & time<=233


***=============================================================================
*** 						Panel A: price response
***=============================================================================

forvalues i=0(1)2 {

	ivreghdfe f`i'.dpre_w `controls0' (l.it12_all = l.Treat) ///
			[aw=peso], ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Table08_PanelA.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'Table08_PanelA.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}


***=============================================================================
*** 						Panel B: employment (SIGE) response
***=============================================================================

forvalues i=0(1)2 {

	gen FC`i'=f`i'.lnL-l.lnL
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' (l.it12_all = l.Treat) ///
			[aw=peso], ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Table08_PanelB.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'Table08_PanelB.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}


***=============================================================================
*** 						Panel C: employment (SSA) response
***=============================================================================

gen lnL_new=log(add_new)*100

forvalues i=0(1)2 {
	capture drop FC`i'
	gen FC`i'=f`i'.lnL_new-l.lnL_new
	capture drop FC`i'_w2 
	winsor FC`i', gen(FC`i'_w2) p(0.025)

	ivreghdfe FC`i'_w2 `controls0' (l.it12_all = l.Treat) ///
			[aw=peso], ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Table08_PanelC.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'Table08_PanelC.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}


***=============================================================================
*** 						Panel D: wages (SSA) response
***=============================================================================

gen lnwage=log(wagebill/add_new)*100
winsor lnwage, gen(lnwage_w) p(0.02)
replace lnwage=lnwage_w

forvalues i=0(1)2 {
	capture drop FC`i'
	gen FC`i'=f`i'.lnwage_w-l.lnwage_w
	capture drop FC`i'_w2 
	winsor FC`i', gen(FC`i'_w2) p(0.02)

	ivreghdfe FC`i'_w2 `controls0' (l.it12_all = l.Treat) ///
			[aw=peso], ffirst dkraay(2) absorb(i.setton5#i.trimestre) 
		
	if `i'==0 {	
		outreg2 using "`out2'Table08_PanelD.dta", replace dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
	else {
		outreg2 using "`out2'Table08_PanelD.dta", append dta dec(3) ///
			addstat("1st stage F stat", e(widstat))	
	}
}

